package org.me.marble;

import android.view.*;
import android.widget.*;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;

/**
 *
 * @author tungi
 */

public class LevelSelection extends Activity implements
        AdapterView.OnItemClickListener{

    @Override
    public void onCreate(Bundle icicle){
        super.onCreate(icicle);
    }
    
    @Override
    public void onResume(){
    	super.onResume();
        
        createView();
    }

    @Override
    public boolean onKeyDown(int keyCode,KeyEvent event){
        if(keyCode==KeyEvent.KEYCODE_BACK)
            return super.onKeyDown(keyCode,event);
        else
            return true;
    }

    public void createView(){
        setContentView(R.layout.levelselection);

        int[] pics=new int[OptionsLibrary.reached_level];
        String[] labels=new String[OptionsLibrary.reached_level];
        boolean[] enables=new boolean[OptionsLibrary.reached_level];

        for(int i=1;i<=OptionsLibrary.reached_level;++i){
            pics[i-1]=getResources().getIdentifier("level"+Integer.toString(i),
                    "drawable",getPackageName());
            labels[i-1]="Level #"+Integer.toString(i);
            enables[i-1]=true;
        }

        ArrayAdapter<String> adapter=new IconArrayAdapter<String>(
                getApplicationContext(),R.layout.iconlistitem,
                R.iconlistitem.icon,R.iconlistitem.label,pics,labels,enables);

        ListView view=(ListView)findViewById(R.list.level);
        view.setAdapter(adapter);
        view.setId(R.list.level);
        view.setOnItemClickListener(this);
        view.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    }

    public void onItemClick(AdapterView<?> arg0,View view,int pos,long id){
        OptionsLibrary.lifes=3;
        OptionsLibrary.points=0;
        OptionsLibrary.current_level=pos+1;
        //start game activity
        Intent intent=new Intent(this,StartActivity.class);
        startActivity(intent);
    }
}
